
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Lib.Utility
{
    public class XMLUtility
    {
        public static XmlDocument LoadXML(string file)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(System.Web.HttpContext.Current.Server.MapPath(file));
            return xdoc;
        }

        static string GetValueByKey(string filepath, string attributetocompare, string valuetocompare, string attributetoget, string err)
        {
            XmlDocument xdoc = LoadXML(filepath);
            XmlNodeList xrootlist = xdoc.GetElementsByTagName("Data");
            if (xrootlist.Count > 0)
            {
                foreach (XmlNode xnode in xrootlist[0].ChildNodes)
                {
                    if (xnode.Attributes[attributetocompare].Value == valuetocompare)
                    {
                        return xnode.Attributes[attributetoget].Value;
                    }
                }
            }

            return err;
        }

        public static string GetAjaxURLByCall(string call)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(System.Web.HttpContext.Current.Server.MapPath("/XMLFiles/AjaxCallURL.xml"));
            XmlNode node = xdoc.SelectSingleNode(string.Format("//Data//Call[@callname='{0}']", call));
            return node.Attributes["url"].Value;
        }

    }
}
